// A-S-M team
// Project: BattleCity

#include "gobject.h"

GObject::GObject()
{
	setXY(ORIGINAL_SCREEN_WIDTH / 2, ORIGINAL_SCREEN_HEIGHT / 2);
	setObjectType(BRICK);
	setSprite(NULL);
	setWidth(0);
	setHeight(0);
	_remove = false;
}

GObject::GObject(CL_String sprite_name, float x, float y, ObjectType type)
{
	setXY(x, y);
	setObjectType(type);
	setSprite(Painter::getInstance()->loadSprite(sprite_name));
	
	CL_Sprite* sprite = getSprite();
	if(sprite != NULL)
	{
		sprite->set_linear_filter(false);
		setWidth((float)sprite->get_width());
		setHeight((float)sprite->get_height());
	}
	else
	{
		cout << sprite_name.data() << " not loaded" << endl;
		setWidth(0);
		setHeight(0);
	}
	_remove = false;
}

GObject::~GObject()
{
	delete _sprite;
}

void GObject::update(int dt)
{
	draw();
}

void GObject::moveTo(float x, float y)
{
	setXY(x, y);
}

void GObject::rotateTo(float angle){
	CL_Sprite* sprite = getSprite();
	if(sprite != NULL)
		sprite->set_angle(CL_Angle::from_degrees(angle));
}

void GObject::draw()
{
	if (_sprite != NULL) 
		Painter::getInstance()->drawSprite(_x, _y, _sprite);
}
	
void GObject::drawPart()
{
	if (_sprite != NULL) 
		Painter::getInstance()->drawSpritePart(_x, _y, _sprite, CL_Rectf(_x,_y,_x+_width, _y+_height));
}